<?php
namespace helper;

use Yii;
use yii\base\Object;

use Qiniu;
use Qiniu\Auth ;
// 引入上传类
use Qiniu\Storage\UploadManager;

class QiniuHelper extends Object
{
    public static $LOG_ROOT_PATH = '/home/work/bkshop_web/logs/'; 
    

    private static	  $ACCESS_KEY = "ySO0WXlGvp82-rkY4-Q_2a9lTxgvJ_fYQHflpaR4" ;
    private static    $SECRET_KEY = "jKEek5vBOiFqDItV6Hexc77CP_k7muuZiwEobJGK" ;
    private static    $BUCKET = "quleyuan-img" ; 
    private static    $DOMAIN = "7xoa92.com2.z0.glb.qiniucdn.com" ; 

    

    public static function uploadQiniu($filePath, $key){
        $auth = new Auth(self::$ACCESS_KEY, self::$SECRET_KEY);
        $upToken = $auth->uploadToken(self::$BUCKET,$key);
      
      


        // 初始化 UploadManager 对象并进行文件的上传。
    	$uploadMgr = new UploadManager();
		list($ret, $err) = $uploadMgr->putFile($upToken, $key, $filePath);
	    // echo "\n====> putFile result: \n";
	    // if ($err !== null) {
	    //     var_dump($err);
	    // } else {
	    //     var_dump($ret);
	    // }
	    return 'http://'.self::$DOMAIN .'/'. $key ; 
    }

    public static function test($a){
        echo $a ; 
    }


    
}
